import { Injectable } from '@nestjs/common';
import config from 'config';
import { createVersionIndexUrl } from '~/utils';

type Route = { gitRepo: string; cdnRoot: string; url: string[], name: string };
const routes = config.get<Route[]>('ROUTES');
const routeMap: { [key: string]: Route } = {};
routes.forEach(route => {
    routeMap[route.name] = route;
});

@Injectable()
export class ConfigService {
    async getMicroApplications() {
        return [{
            name: 'team1-admin-test',
            activeHash: '#/team1',
        },
        {
            name: 'team2-admin-test',
            activeHash: '#/team2',
        }].map(item => ({
            ...item,
            entry: createVersionIndexUrl(routeMap[item.name].cdnRoot).replace('index.html',''),
        }))
    }
}
